package Day08_17;

import java.util.Comparator;
import java.util.TreeSet;

public class Test_TreeSet01 {
    public static void main(String[] args) {
        TreeSet<Month> ts = new TreeSet<>(new Comparator<Month>() {
            @Override
            public int compare(Month o1, Month o2) {
                return o1.month - o2.month;
            }
        });
        Month m1 = new Month(1);
        Month m4 = new Month(4);
        Month m3 = new Month(3);
        Month m2 = new Month(2);

        ts.add(m1);
        ts.add(m2);
        ts.add(m3);
        ts.add(m4);
        for (Month i:ts){
            System.out.println(i); //Day08_17.Month cannot be cast to java.lang.Comparable 无法转换为某个对象！
        }
    }
}
class Month {
     int month;

    public Month() {
    }

    public Month(int month) {
        this.month = month;
    }

    public String toString() {
        return "month = "+this.month;
    }
}
class MonthComparator01 implements Comparator<Month> {
    public int compare(Month o1,Month o2){
            return o1.month - o2.month;
    }
}
class MonthComparator02 implements Comparator<Month> {
    public int compare(Month o1,Month o2){
        return o2.month - o1.month;
    }
}
